import request from '@/utils/request'

function url(u) {
  const prefix = '/a/user'
  return `${prefix}${u || ''}`
}

export function findUser(state, page, size) {
  return request({
    url: url(),
    method: 'get',
    params: { state, page, size }
  })
}

/**
 *
 * @param {object} user
 * @param {string} user.id
 * @param {string} user.name
 * @param {string} user.password
 * @param {string} user.dept
 * @param {string} user.email
 * @param {string} user.tel
 * @param {string} user.faceuri
 */
export function addUser(user) {
  return request({
    url: url(),
    method: 'post',
    data: user
  })
}

export function batchAddUser(user) {
  return request({
    url: url('/batch'),
    method: 'post',
    data: user
  })
}

export function updateUser(user) {
  return request({
    url: url(),
    method: 'put',
    data: user
  })
}

export function deleteUser(id) {
  return request({
    url: url(`/${id}`),
    method: 'delete'
  })
}

export function enableUser(id) {
  return request({
    url: url(`/${id}/enable`),
    method: 'put'
  })
}
